package com.mygdx.game.group;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.mygdx.game.MainGame;
import com.mygdx.game.group.basegroup.BaseGroup;
import com.mygdx.game.resource.Res;

public class DialogGroup extends BaseGroup {


    public DialogGroup(MainGame mainGame, String message) {
        super(mainGame);
        init(message);
    }

    public void init(String message) {
        setSize(getMainGame().getWorldWidth() - 40, getMainGame().getWorldHeight() / 5);

        //背景
        Image bgImage = new Image(getMainGame().getTextureAtlas().findRegion(Res.Atlas.GAME_BLANK));
        bgImage.setColor(new Color(0, 0, 0, 0.2f));
        bgImage.setScale(getWidth() / bgImage.getWidth(), getHeight() / bgImage.getHeight());
        bgImage.setPosition(0, 0);
        addActor(bgImage);

        /**
         * 提示框标题
         */
        Label.LabelStyle style = new Label.LabelStyle();
        style.font = getMainGame().getBitmapFont();
        Label title = new Label(message, style);
        title.setFontScale(0.4f);
        //标签和标题同大小
        title.setSize(title.getPrefWidth(), title.getPrefHeight());
        title.setPosition(getWidth() / 2 - title.getWidth() / 2, getHeight() - title.getHeight());//水平居中置顶
        addActor(title);

        //退出游戏
        Image btnOk = new Image(getMainGame().getTextureAtlas().findRegion(Res.Atlas.DIALOG_BTN_OK));
        btnOk.setPosition(10, 10);
        btnOk.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                Gdx.app.exit();//退出游戏
            }
        });
        addActor(btnOk);

        //返回游戏
        Image btnCancel = new Image(getMainGame().getTextureAtlas().findRegion(Res.Atlas.DIALOG_BTN_cancel));
        btnCancel.setPosition(getWidth() - btnCancel.getWidth() - 10, 10);
        btnCancel.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                getMainGame().getGameScreen().setShowExitConfirmStage(false);
            }
        });
        addActor(btnCancel);

    }
}
